import 'package:connectivity/connectivity.dart';
import 'package:flutter_permissions/flutter_permissions_platform_interface.dart';
import 'package:flutter_permissions/flutter_permissions.dart';
import 'package:utils/plugins/flutter_utils.dart';

class NetworkUtil {
  NetworkUtil._();

  /// TODO 网络连接
  static Future<bool> isConnected() async {
    if (await FlutterPermissions.requestPermission(
            Permission.AccessNetworkState) ==
        PermissionStatus.authorized) {
      var connectivityResult = await (Connectivity().checkConnectivity());
      return connectivityResult != ConnectivityResult.none;
    }
    return false;
  }

  /// TODO 当前连接网络
  static Future<String> getCurrentNetworkType() async {
    var connectivityResult = await (Connectivity().checkConnectivity());
    if (connectivityResult == ConnectivityResult.mobile) {
      // 网络类型为移动网络
      return FlutterUtils.getCurrentNetworkType();
    } else if (connectivityResult == ConnectivityResult.wifi) {
      // 网络类型为WIFI
      return "Wi-Fi";
    }
    return "未知";
  }

  /// TODO wifi mac 地址
  static Future<String> getWifiMac() async {
    if (await FlutterPermissions.requestPermission(
            Permission.AccessFineLocation) ==
        PermissionStatus.authorized) {
    }
    return "";
  }
}
